﻿using System;
using System.Data;

namespace org.se.fs.model.Table
{
    public class RegularLoan : DataContext
    {
        public DataTable GetLists(UInt16 page, UInt16 size, string filterString)
        {
            using (var databaseManager = GetDatabase())
            {
                databaseManager.Open();
                databaseManager.CreateParameters(3);
                databaseManager.AddParameters(0, "page", page);
                databaseManager.AddParameters(1, "size", size);
                databaseManager.AddParameters(2, "filterString", filterString);
                var dataSet = databaseManager.ExecuteDataSet(CommandType.StoredProcedure, "GetRegularLoanLists");
                return ToDataTable(dataSet);
            }
        }

        public UInt16 GetCount()
        {
            using (var databaseManager = GetDatabase())
            {
                databaseManager.Open();
                var result = databaseManager.ExecuteScalar(CommandType.StoredProcedure, "GetCountRegularLoan");
                return Convert.ToUInt16(result);
            }
        }

        public UInt64 Insert(string name, string code, string address, string email, string faxNum, string mobileNum, string telNum, UInt64 userId)
        {
            //using (var databaseManager = GetDatabase())
            //{
            //    databaseManager.Open();
            //    databaseManager.CreateParameters(8);
            //    databaseManager.AddParameters(0, "name", name);
            //    databaseManager.AddParameters(1, "code", code);
            //    databaseManager.AddParameters(2, "address",address );
            //    databaseManager.AddParameters(3, "email", email);
            //    databaseManager.AddParameters(4, "fax_num", faxNum);
            //    databaseManager.AddParameters(5, "mobile_num",mobileNum );
            //    databaseManager.AddParameters(6, "tel_num",telNum );
            //    databaseManager.AddParameters(7, "user_create_id", userId);
            //    var result = databaseManager.ExecuteScalar(CommandType.StoredProcedure, "InsertRegularLoan");
            //    return Convert.ToUInt64(result);
            //}
            return 0;
        }

        public bool Update(UInt64 id, string name, string code, string address, string email, string faxNum, string mobileNum, string telNum, UInt64 userId)
        {
            //using (var databaseManager = GetDatabase())
            //{
            //    databaseManager.Open();
            //    databaseManager.CreateParameters(9);
            //    databaseManager.AddParameters(0, "id", id);
            //    databaseManager.AddParameters(1, "name", name);
            //    databaseManager.AddParameters(2, "code", code);
            //    databaseManager.AddParameters(3, "address", address);
            //    databaseManager.AddParameters(4, "email", email);
            //    databaseManager.AddParameters(5, "fax_num", faxNum);
            //    databaseManager.AddParameters(6, "mobile_num", mobileNum);
            //    databaseManager.AddParameters(7, "tel_num", telNum);
            //    databaseManager.AddParameters(8, "user_create_id", userId);
            //    var result = databaseManager.ExecuteNonQuery(CommandType.StoredProcedure, "UpdateRegularLoan");
            //    return Convert.ToBoolean(result);
            //}
            return false;
        }

        public bool Delete(UInt64 uid)
        {
            //using (var databaseManager = GetDatabase())
            //{
            //    databaseManager.Open();
            //    databaseManager.CreateParameters(1);
            //    databaseManager.AddParameters(0, "id", uid);
            //    var result = databaseManager.ExecuteNonQuery(CommandType.StoredProcedure, "DeleteRegularLoan");
            //    return Convert.ToBoolean(result);
            //}
            return false;
        }
    }
}
